// Created by carolsail

import { ENUM_AUDIO_CLIP, ENUM_GAME_STATUS, ENUM_UI_TYPE } from "../Enum";
import { StaticInstance } from './../StaticInstance';
import AudioManager from "../manager/AudioManager";
import BaseLayer from "./Baselayer";
import DataManager from "../manager/DataManager";
import SdkManager from "../manager/SdkManager";
import { privacyChannel } from "../Script/privacyChannel";
import { privacyChannelKS } from "../Script/privacyChannelKS";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CommonBarLayer extends BaseLayer {
    btnClose: cc.Node = null
    reward: cc.Node = null;;
    // noReward: cc.Node = null
    gameName: cc.Node = null
    protected onLoad(): void {
        this.btnClose = cc.find('Canvas/UI/CommonBarLayer/style/panel/close')
        this.btnClose.on('click', this.onCloseClick, this)
        this.reward = cc.find("Canvas/UI/CommonBarLayer/style/panel/button")
        this.reward.on('click', this.getReward, this)
        //this.noReward = cc.find("Canvas/UI/CommonBarLayer/style/panel/button1")
        this.gameName = cc.find("Canvas/UI/CommonBarLayer/style/panel/bottom/gameName")

        //this.noReward.on('click', this.getReward, this)
    }
    show() {
        super.show()
        // console.error("是不是来自于侧边栏", (privacyChannel.getChannel() as privacyChannelKS).isComeFromSliderBar())
        // console.error("是不是可以领取奖励", (privacyChannel.getChannel() as privacyChannelKS).isRewarded());
        this.gameName.getComponent(cc.Label).string = privacyChannel.getChannel().gameName
        this.reward.active = true


        // if ((privacyChannel.getChannel() as privacyChannelKS).isComeFromSliderBar()) {//从侧边栏来
        //     if ((privacyChannel.getChannel() as privacyChannelKS).isRewarded()) { //可以领取
        //         this.reward.active = true
        //         this.noReward.active = false
        //     } else {
        //         this.reward.active = false
        //         this.noReward.active = true
        //     }
        // } else {
        //     this.reward.active = false
        //     this.noReward.active = false
        // }


        // if ((privacyChannel.getChannel() as privacyChannelKS).channelObj.checkSliderBarIsAvailable()) {
        //     this.siderBar.active = true
        // } else {
        //     this.siderBar.active = false
        // }
    }


    onCloseClick() {
        AudioManager.instance.playSound(ENUM_AUDIO_CLIP.CLICK)
        StaticInstance.uiManager.toggle(ENUM_UI_TYPE.CommonBarLayer, false)
        StaticInstance.uiManager.toggle(ENUM_UI_TYPE.MENU)
    }

    getReward() {
        AudioManager.instance.playSound(ENUM_AUDIO_CLIP.CLICK)
        DataManager.instance.power += 5
        DataManager.instance.save();
        (privacyChannel.getChannel() as privacyChannelKS).addCommonUse()
        StaticInstance.uiManager.toggle(ENUM_UI_TYPE.CommonBarLayer, false)
        StaticInstance.uiManager.toggle(ENUM_UI_TYPE.MENU);

    }
}



